package p270jp.pxv.android.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import p064c6.Preconditions;
import p134ei.AnalyticsAction;
import p134ei.LikeButtonAnalytics;
import p134ei.PixivAnalytics;
import p159fi.FirebaseAnalyticsEvent;
import p165fo.C3114c;
import p165fo.Subscribe;
import p184gi.AnalyticsParameter;
import p184gi.LikeEvent;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.event.UpdateLikeEvent;
import p270jp.pxv.android.legacy.model.PixivIllust;
import p270jp.pxv.android.legacy.model.PixivNovel;
import p270jp.pxv.android.legacy.model.PixivWork;
import p274k2.ContextCompat;
import p325m0.MutabilityOwnership;
import p346ml.MyWorkService;
import p347mm.WorkUtils;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p671zc.CompositeDisposable;

/* compiled from: FloatingLikeButton.kt */
/* renamed from: jp.pxv.android.view.FloatingLikeButton */
/* loaded from: classes2.dex */
public final class FloatingLikeButton extends FloatingActionButton implements LikeButtonView, LikeButtonAnalytics, View.OnClickListener, View.OnLongClickListener, AbstractC5475a {

    /* renamed from: r */
    public final CompositeDisposable f19502r = new CompositeDisposable();

    /* renamed from: s */
    public final AbstractC6949c f19503s = Preconditions.m9802P(1, new C4371a(this, null, null));

    /* renamed from: t */
    public final AbstractC6949c f19504t = Preconditions.m9802P(1, new C4372b(this, null, null));

    /* renamed from: u */
    public final AbstractC6949c f19505u = Preconditions.m9802P(1, new C4373c(this, null, null));

    /* renamed from: v */
    public PixivWork f19506v;

    /* renamed from: w */
    public AnalyticsParameter f19507w;

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.view.FloatingLikeButton$a */
    /* loaded from: classes2.dex */
    public static final class C4371a extends Lambda implements AbstractC3435a<PixivAnalytics> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19508a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4371a(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19508a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ei.e, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final PixivAnalytics invoke() {
            return this.f19508a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(PixivAnalytics.class), null, null);
        }
    }

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.view.FloatingLikeButton$b */
    /* loaded from: classes2.dex */
    public static final class C4372b extends Lambda implements AbstractC3435a<WorkUtils> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19509a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4372b(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19509a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [mm.x, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final WorkUtils invoke() {
            return this.f19509a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(WorkUtils.class), null, null);
        }
    }

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.view.FloatingLikeButton$c */
    /* loaded from: classes2.dex */
    public static final class C4373c extends Lambda implements AbstractC3435a<MyWorkService> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19510a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4373c(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19510a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ml.a, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final MyWorkService invoke() {
            return this.f19510a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(MyWorkService.class), null, null);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FloatingLikeButton(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(attributeSet, "attrs");
        Context context2 = getContext();
        MutabilityOwnership.m3746l(context2, "context");
        TypedValue typedValue = new TypedValue();
        if (context2.getTheme().resolveAttribute(R.attr.colorCharcoalSurface9, typedValue, true)) {
            setBackgroundTintList(ColorStateList.valueOf(typedValue.data));
            setOnClickListener(this);
            setOnLongClickListener(this);
            return;
        }
        throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
    }

    private final MyWorkService getMyWorkService() {
        return (MyWorkService) this.f19505u.getValue();
    }

    private final PixivAnalytics getPixivAnalytics() {
        return (PixivAnalytics) this.f19503s.getValue();
    }

    private final WorkUtils getWorkUtils() {
        return (WorkUtils) this.f19504t.getValue();
    }

    @Override // p134ei.LikeButtonAnalytics
    /* renamed from: a */
    public void mo4492a() {
        PixivAnalytics.m6529a(getPixivAnalytics(), 2, AnalyticsAction.DISLIKE_VIA_WORK, null, 4);
    }

    @Override // p134ei.LikeButtonAnalytics
    /* renamed from: c */
    public void mo4491c() {
        FirebaseAnalyticsEvent aVar;
        AnalyticsParameter cVar = this.f19507w;
        if (cVar != null) {
            PixivWork pixivWork = this.f19506v;
            if (pixivWork != null) {
                if (pixivWork instanceof PixivIllust) {
                    aVar = new LikeEvent.C3348d(pixivWork.f19079id, cVar.f15553b, cVar.f15552a);
                } else if (pixivWork instanceof PixivNovel) {
                    aVar = new LikeEvent.C3352h(pixivWork.f19079id, cVar.f15553b, cVar.f15552a, 2);
                } else {
                    throw new IllegalStateException();
                }
                getPixivAnalytics().m6526d(aVar);
                return;
            }
            MutabilityOwnership.m3737u("work");
            throw null;
        }
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void disabledView() {
        setEnabled(false);
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void enabledView() {
        setEnabled(true);
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }

    @Override // com.google.android.material.floatingactionbutton.FloatingActionButton, android.widget.ImageView, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        C3114c.m6284b().m6276j(this);
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View view) {
        MutabilityOwnership.m3745m(view, "v");
        WorkUtils workUtils = getWorkUtils();
        PixivWork pixivWork = this.f19506v;
        if (pixivWork != null) {
            workUtils.m3531c(pixivWork, this.f19502r, this, this);
        } else {
            MutabilityOwnership.m3737u("work");
            throw null;
        }
    }

    @Override // com.google.android.material.floatingactionbutton.FloatingActionButton, android.widget.ImageView, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.f19502r.m80f();
        C3114c.m6284b().m6274l(this);
    }

    @Subscribe
    public final void onEvent(UpdateLikeEvent updateLikeEvent) {
        MutabilityOwnership.m3745m(updateLikeEvent, "event");
        WorkUtils workUtils = getWorkUtils();
        PixivWork pixivWork = this.f19506v;
        if (pixivWork == null) {
            MutabilityOwnership.m3737u("work");
            throw null;
        } else if (workUtils.m3533a(pixivWork) == getWorkUtils().m3533a(updateLikeEvent.getWork())) {
            long workId = updateLikeEvent.getWorkId();
            PixivWork pixivWork2 = this.f19506v;
            if (pixivWork2 == null) {
                MutabilityOwnership.m3737u("work");
                throw null;
            } else if (workId != pixivWork2.f19079id) {
            } else {
                if (pixivWork2 != null) {
                    pixivWork2.isBookmarked = updateLikeEvent.isBookmarked();
                    m4496v();
                    return;
                }
                MutabilityOwnership.m3737u("work");
                throw null;
            }
        }
    }

    @Override // android.view.View.OnLongClickListener
    public boolean onLongClick(View view) {
        MutabilityOwnership.m3745m(view, "v");
        AnalyticsParameter cVar = this.f19507w;
        if (cVar == null) {
            return false;
        }
        WorkUtils workUtils = getWorkUtils();
        PixivWork pixivWork = this.f19506v;
        if (pixivWork != null) {
            return workUtils.m3532b(pixivWork, cVar.f15552a);
        }
        MutabilityOwnership.m3737u("work");
        throw null;
    }

    public final void setAnalyticsParameter(AnalyticsParameter cVar) {
        MutabilityOwnership.m3745m(cVar, "parameter");
        this.f19507w = cVar;
    }

    public final void setWork(PixivWork pixivWork) {
        MutabilityOwnership.m3745m(pixivWork, "work");
        this.f19506v = pixivWork;
        m4496v();
    }

    /* renamed from: t */
    public final void m4498t() {
        Context context = getContext();
        Object obj = ContextCompat.f19963a;
        Drawable b = ContextCompat.C4472c.m4259b(context, R.drawable.ic_fab_liked);
        if (b != null) {
            Context context2 = getContext();
            MutabilityOwnership.m3746l(context2, "this.context");
            TypedValue typedValue = new TypedValue();
            if (context2.getTheme().resolveAttribute(R.attr.colorCharcoalLike, typedValue, true)) {
                b.setTint(typedValue.data);
                setImageDrawable(b);
                return;
            }
            throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
        }
        throw new IllegalArgumentException("Required value was null.".toString());
    }

    /* renamed from: u */
    public final boolean m4497u() {
        MyWorkService myWorkService = getMyWorkService();
        PixivWork pixivWork = this.f19506v;
        if (pixivWork != null) {
            if (!myWorkService.m3554a(pixivWork)) {
                PixivWork pixivWork2 = this.f19506v;
                if (pixivWork2 != null) {
                    if (!pixivWork2.visible) {
                        if (pixivWork2 == null) {
                            MutabilityOwnership.m3737u("work");
                            throw null;
                        } else if (pixivWork2.isBookmarked) {
                        }
                    }
                    return true;
                }
                MutabilityOwnership.m3737u("work");
                throw null;
            }
            return false;
        }
        MutabilityOwnership.m3737u("work");
        throw null;
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void updateViewWithDisliked() {
        setImageResource(R.drawable.ic_fab_like);
        if (m4497u()) {
            m8527k();
            m8520r();
        }
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void updateViewWithLiked() {
        m4498t();
        if (m4497u()) {
            m8527k();
            m8520r();
        }
    }

    /* renamed from: v */
    public final void m4496v() {
        PixivWork pixivWork = this.f19506v;
        if (pixivWork != null) {
            if (pixivWork.isBookmarked) {
                m4498t();
            } else {
                setImageResource(R.drawable.ic_fab_like);
            }
            if (m4497u()) {
                m8527k();
                m8520r();
                return;
            }
            m8527k();
            return;
        }
        MutabilityOwnership.m3737u("work");
        throw null;
    }
}
